import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gameplay_flutter/lib_runtime/extension/string_extension/string_text.dart';
import 'package:gameplay_flutter/lib_runtime/extension/widget/widget_wrapper.dart';
import '../../../../lib_basemodel/chat_room/kh_mic_seat_user_info_model.dart';
import '../../../../lib_baseview/lib_baseview.dart';
import '../../../../resource/language/generated/l10n.dart';

class MicSeatUserInfoWidget extends StatelessWidget {
  /// 是否是房间拥有者
  /// 房间拥有者底部有额外四个操作按钮
  final bool? isRoomOwner;

  final KhMicSeatUserInfoModel? model;

  const MicSeatUserInfoWidget({super.key, this.isRoomOwner, this.model});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 313 + 41 + 10 + 9 + 8 + 10,
      child: Stack(
        alignment: AlignmentDirectional.bottomCenter,
        children: [
          Container(
            height: 313 + 10 + 9 + 8 + 10,
            decoration: const BoxDecoration(
              color: Color(0xFFFFFFFF),
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(18),
                topRight: Radius.circular(18),
              ),
            ),
          ),
          Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  image('room/room_report_icon.png', width: 18, height: 18)
                      .padding(start: 15),
                  Stack(
                    alignment: AlignmentDirectional.bottomEnd,
                    children: [
                      model?.headPortraitsUrl != null
                          ? image(
                              model!.headPortraitsUrl!,
                              width: 82,
                              height: 82,
                            ).corner(radius: 82 / 2.0)
                          : const SizedBox(
                              width: 82,
                              height: 82,
                            ),
                      image(
                          model?.isAttention == 1
                              ? 'room/room_follow.png'
                              : 'room/room_un_follow.png',
                          width: 32,
                          height: 32),
                    ],
                  ),
                  const SizedBox(width: 18, height: 18).padding(end: 15),
                ],
              ),
              const SizedBox(height: 15),

              // 用户信息
              Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  userInfoWidget((model?.fans.toString()) ?? '', 'following'),
                  Container(
                    color: const Color(0xFFE4E4E4),
                    width: 1,
                    height: 40,
                  ),
                  userInfoWidget((model?.fans.toString()) ?? '', 'followers'),
                  Container(
                    color: const Color(0xFFE4E4E4),
                    width: 1,
                    height: 40,
                  ),
                  userInfoWidget(model?.giftNum, 'gifts'),
                ],
              ),
              const SizedBox(height: 10),
              Row(
                mainAxisSize: MainAxisSize.min,
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  model?.gender == 0
                      ? const SizedBox(width: 18, height: 18)
                      : image(
                              model?.gender == 1
                                  ? 'me/icon_nan.png'
                                  : 'me/icon_nv.png',
                              width: 18,
                              height: 18)
                          .padding(end: 5),
                  (model?.nickname ?? '').text(
                      color: const Color(0xFF000000),
                      fontSize: 20,
                      weight: TextFontWeight.medium),
                  const SizedBox(width: 18, height: 18)
                ],
              ),

              (model?.about ?? '').text(
                  color: const Color(0xFFC1C1C1),
                  fontSize: 11,
                  weight: TextFontWeight.regular),

              (isRoomOwner ?? false)
                  ? const SizedBox(
                      height: 40,
                    )
                  : const SizedBox(
                      height: 56,
                    ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  userInfoTopControls(
                      'room/room_info_gift.png', T.current.room9_send_gifts),
                  userInfoTopControls(
                      'room/room_info_message.png', T.current.room9_go_chats),
                  userInfoTopControls(
                      'room/room_info_follow.png', T.current.room9_follow_room),
                  userInfoTopControls(
                      'room/room_info_homepage.png', T.current.room9_homepage),
                ],
              ).padding(start: 32, end: 32),
              const Spacer(),
              const SizedBox(height: 8),
              if (isRoomOwner ?? false)
                SafeArea(
                  child: userBottomWidget(),
                ),
            ],
          ),
        ],
      ),
    );
  }

  Widget userInfoWidget(String? countStr, String desc) {
    return SizedBox(
      width: 83,
      child: Column(
        children: [
          (countStr ?? '').text(color: const Color(0xFF000000), fontSize: 18),
          desc.text(color: const Color(0xFFC1C1C1), fontSize: 12)
        ],
      ),
    );
  }

  Widget userInfoTopControls(String iconStr, String desc) {
    return Column(
      children: [
        image(iconStr, width: 48, height: 48),
        desc.text(color: const Color(0xFFC1C1C1), fontSize: 12)
      ],
    );
  }

  // 底部 四个操作按钮
  Widget userBottomWidget() {
    return Column(
      children: [
        Container(
          width: ScreenUtil().screenWidth,
          height: 1,
          color: const Color(0xFFF2F2F2),
        ),
        const SizedBox(height: 8),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            image('room/room_close_voice_icon.png', width: 30, height: 30),
            image('room/room_owner_line.png', width: 2, height: 28),
            image('room/room_close_mic_icon.png', width: 30, height: 30),
            image('room/room_owner_line.png', width: 2, height: 28),
            image('room/room_close_icon.png', width: 30, height: 30),
            image('room/room_owner_line.png', width: 2, height: 28),
            image('room/room_ext_icon.png', width: 30, height: 30),
          ],
        ).padding(start: 40, end: 40, bottom: 10),
      ],
    );
  }
}
